class Solution(object):
    def isPrefixString(self, s, words):
        n = len(s)
        ans = 0
        k = 0
        m = len(words)
        while k < m:
            ans += len(words[k])
            if ans == n:
                break
            if ans > n:
                return False
            k += 1
        return s == ''.join(words[: k + 1])
